<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1">
    <title>Zotero Library</title>
    <link rel="icon" href="/static/icons/zotero_128x128x32.png" type="image/png">
    <link rel="stylesheet" href="/static/index.css">
    <style>

    </style>
</head>

<body>
    <div class="header-container">
        <h1>
            <img src="/static/icons/zotero-logo-512x123.svg" alt="Zotero Logo" style="height: 2rem;">
        </h1>
        <input type="text" id="searchBox" placeholder="Search in page...">
    </div>

    <div style="text-align: right; margin-bottom: 20px;">
        <a href="{{ request.app.router['monitor'].url_for() }}">查看服务器监控</a>
    </div>

    <ul id="fileList">
        {% for f in files %}
        <li><a href="{{ request.app.router['view_file'].url_for(filename=f) }}">{{ f }}</a></li>
        {% endfor %}
    </ul>

    <script>
        // 搜索功能
        document.getElementById('searchBox').addEventListener('input', function () {
            const searchTerm = this.value.trim().toLowerCase();

            document.querySelectorAll('#fileList li').forEach(function (item) {
                const anchor = item.querySelector('a');
                const originalText = anchor.textContent;
                const lowerText = originalText.toLowerCase();

                if (searchTerm === "") {
                    anchor.innerHTML = originalText;
                    item.style.display = '';
                    return;
                }

                if (lowerText.includes(searchTerm)) {
                    // 高亮匹配的关键词
                    const regex = new RegExp(`(${searchTerm})`, 'gi');
                    const highlightedText = originalText.replace(regex, `<span class="highlight">$1</span>`);
                    anchor.innerHTML = highlightedText;
                    item.style.display = '';
                } else {
                    item.style.display = 'none';
                }
            });
        });
    </script>
</body>

</html>